import React from 'react';
import {withRouter} from 'react-router-dom';
import {Menu, Icon} from 'antd';
import {inject} from 'mobx-react';

@inject ('store')
@withRouter
export default class UserMenu extends React.PureComponent {
  logout = item => {
    console.log ('click', item);
    const {history} = this.props;
    switch (item.key) {
      case 'logout':
        this.props.store.setLogout ();
        break;
      case 'password':
        history.push ('/home/modifyPassword');
        // location.go('/home/modifyPassword');
        break;
      case 'identify':
        history.push ('/home/identify');
        break;
      default:
    }
  };
  render () {
    const {pathname} = this.props.location;
    const isPasswordPage = pathname === '/home/modifyPassword';
    const isIdentifyPage = pathname === '/home/identify';

    return (
      <Menu className="user-menu" onClick={this.logout}>
        <Menu.Item
          key="identify"
          style={{display: !isIdentifyPage ? 'block' : 'none'}}
        >
          资料修改
        </Menu.Item>
        <Menu.Item
          key="password"
          style={{display: !isPasswordPage ? 'block' : 'none'}}
        >
          修改密码
        </Menu.Item>
        <Menu.Divider />
        <Menu.Item key="logout"><Icon type="logout" />退出登录</Menu.Item>
      </Menu>
    );
  }
}
